/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.api.wlhy.notify;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.ArrayListDict;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.wlhy.hywarningmessage.entity.HyWarningMessage;
import org.jeecg.modules.wlhy.hywarningmessage.service.IHyWarningMessageService;
import org.jeecg.modules.wlhy.utils.UserUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * 消息通知
 *
 * @author duanlikao
 * @created 2020/12/23
 */
@Api(tags="APP消息通知")
@RestController
@RequestMapping("/api/wlhy/notify")
@Slf4j
public class ApiNotifyController extends JeecgController <HyWarningMessage, IHyWarningMessageService> {

    @Autowired
    private IHyWarningMessageService hyWarningMessageService;

    @Autowired
    private UserUtil userUtil;

    private static final Logger LOGGER = LoggerFactory.getLogger(ApiNotifyController.class);

    @AutoLog(value = "告警消息-通过id关闭")
    @ApiOperation(value="告警消息-通过id关闭", notes="告警消息-通过id关闭")
    @PostMapping(value = "/closeWarning")
    public Result <?> closeWarning(@RequestParam(name="id")  String  id) {

        HyWarningMessage hyWarningMessageDb  = hyWarningMessageService.getById(id);
        if(hyWarningMessageDb==null){
            return Result.error("未找到对应数据!");
        }

        LoginUser loginUser = UserUtil.getLoginUser();
        HyWarningMessage hyWarningMessage = new HyWarningMessage();
        hyWarningMessage.setId(id);
        hyWarningMessage.setMessageStatus(2);
        hyWarningMessage.setUpdateBy(loginUser.getUsername());
        hyWarningMessage.setUpdateTime(new Date());
        hyWarningMessageService.updateById(hyWarningMessage);
        return Result.OK("关闭成功!");
    }

//    @AutoLog(value = "告警消息-获取用户消息")
    @ApiOperation(value="告警消息-获取用户消息", notes="告警消息-获取用户消息")
    @GetMapping(value = "/getWarningMessage")
    @ArrayListDict
    public Result<?> getWarningMessage() {
        LoginUser loginUser = UserUtil.getLoginUser();
        return hyWarningMessageService.getMessageByUserId(loginUser.getId());
    }

}